package com.qef.com.mmovie.mvp.adapter;

import android.content.Context;
import android.support.v4.view.ViewCompat;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.qef.com.mmovie.R;
import com.qef.com.mmovie.base.BaseRecycerViewAdapter;
import com.qef.com.mmovie.entity.LaughImgEntity;
import com.qef.com.mmovie.img.ImageLoader;
import com.qef.com.mmovie.utils.DateUtil;

import java.util.List;

/**
 * Created by feq on 2017/4/3.
 */

public class LaughImgAdapter extends BaseRecycerViewAdapter<LaughImgEntity.DataEntity, RecyclerView.ViewHolder> {
    List<LaughImgEntity.DataEntity> dataBeanxes;
    Context context;

    public LaughImgAdapter(Context context, List<LaughImgEntity.DataEntity> list) {
        super(context, list);
        dataBeanxes = list;
        this.context = context;
    }

    @Override
    public RecyclerView.ViewHolder getCreateViewHolder(ViewGroup parent, int viewType) {
//        View view = View.inflate(App.getInstance(), R.layout.item_laughimg, null);
        return new MyHolder(inflater.inflate(R.layout.item_laughimg, parent, false));
    }

    @Override
    public void getBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        LaughImgEntity.DataEntity itemListBean = list.get(position);
        if (holder instanceof MyHolder) {
            MyHolder myHolder = (MyHolder) holder;
            ViewCompat.setTransitionName(myHolder.imageView, String.valueOf(position) + "_image");
            ImageLoader.loadAll(context, itemListBean.getImage(), myHolder.imageView);


            myHolder.itemView.setOnClickListener(v -> {
                if (mClickListener != null) {
                    mClickListener.onItemClick(position, v, myHolder);
                }
            });


            myHolder.textView.setText(itemListBean.getTitle());
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append("#").append(itemListBean.getCates().get(0).getCatename())
                    .append(" ")
                    .append(" / ")
                    .append(" ")
                    .append(DateUtil.formatTime2(Long.parseLong(itemListBean.getDuration())));
            myHolder.description.setText(stringBuilder.toString());
        }
    }


    public static class MyHolder extends RecyclerView.ViewHolder {
        public TextView textView;
        public TextView description;
        public ImageView imageView;

        public MyHolder(View itemView) {
            super(itemView);
            textView = ((TextView) itemView.findViewById(R.id.title));
            description = ((TextView) itemView.findViewById(R.id.description));
            imageView = ((ImageView) itemView.findViewById(R.id.img));
        }
    }

}
